<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <style>
        div{
            width: 200px;
            height: 200px;
            background-color: red;
        }
        div p{
            width: 100px;
            height: 100px;
            background-color: blue;
        }
    </style>
</head>
<body>
<div>
    <p></p>
</div>
<script>
    let divObj = document.getElementsByTagName('div')[0];
    let pObj = divObj.getElementsByTagName('p')[0];
    divObj.onclick = function(){
        alert('父元素的点击事件被触发');
    }
    pObj.onclick = function(event){
        alert('子元素的点击事件被触发');
        event.cancelBubble = true;
    }
</script>
</body>
</body>
</html>